import * as echarts from "echarts";
type EChartsOption = echarts.EChartsOption;
//生成1-31的数组
const xArr: number[] = Array(31)
  .fill(1)
  .map((v, k) => k + 1);
const yArr: number[] = Array(31).fill(0);
const setLineChartOpt = (data: monthDataType[], title: string) => {
  data.map((value) => {
    yArr[value.key] = value.value;
    return value;
  });

    const option: EChartsOption = {

    title: {
      left: "center",
      text: title,
      textStyle: {
        fontSize: 16,
        fontWeight: 400,
      },
    },
    legend: {
      show: true,
      orient: "vertical",
      left: "left",
    },
    tooltip: {
        trigger: "axis",
        
    //   axisPointer: {
    //     label: {
    //         show:false
    //     },
    //   },
    },

    xAxis: {
      type: "category",
      data: xArr,
      axisLabel: {
        interval: 5,
        fontSize: 12,
      },
      axisTick: {
        show: false,
      },
    },
    yAxis: {
      type: "value",
      axisLabel: {
          fontSize: 10,
          margin: 3
      },
        boundaryGap: [0, "30%"],
      
    },
    series: [
      {
        name: title.slice(-2),
        data: yArr,
        type: "line",
        markPoint: {
          data: [
            { type: "max", name: "Max" },
        
                { type: "average", name: "Average" },
            
            ],
            label: {
                fontSize: 11,
            
            }
        },
        markLine: {
            data: [{ type: "average", name: "Avg" }],
            label: {
                show:false
            }
        },
        lineStyle: {
          color: "#5470C6",
          width: 2,
            },
            label: {
            fontSize: 14
        }
      },
    ],
  };
  return option;
};

export { setLineChartOpt };
